package com.lcp.dingqibao.controller;

import com.lcp.abstraction.AppHolderService;
import com.lcp.abstraction.IColumnRemoteService;
import com.lcp.coremodel.DbEntity;
import com.lcp.dingqibao.model.OAUserModel;
import com.lcp.dingqibao.service.DingProcessService;
import com.lcp.qibao.response.ResponseData;
import com.lcp.qibao.service.UserInfoService;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/dingding")
@RestController
public class DingQiBaoController {

    @Autowired
    DingProcessService dingProcessService;

    @Autowired
    AppHolderService appHolderService;


    @Autowired
    UserInfoService userInfoService;
    @Qualifier("userInfoByCodeServiceImpl")
    @Autowired
    IColumnRemoteService userInfoServiceByCode;

    @GetMapping("getProcessList")
    public List<DbEntity> getProcessList() {
        DbEntity enUser = userInfoServiceByCode.getCacheDataByKey(appHolderService.getUser().getCode());
        if (enUser == null || enUser.getId() == null) {
            return new ArrayList<>();
        }
        List<DbEntity> list = dingProcessService.getAllProcessListByUserId(enUser.getId().toString());
        return list;
    }

    @GetMapping("/getApprovalForm")
    public ResponseData<Object> getApprovalForm(String oInsId) {
        if (StringUtils.isEmpty(oInsId)) {
            return ResponseData.parameterNotFound("oInsId");
        }
        var data = dingProcessService.getApprovalForm(oInsId);
        return ResponseData.success(data);
    }

    @GetMapping("/getQBToken")
    public String getLoginUser(@RequestParam String deptName) {
        OAUserModel userBo = new OAUserModel();
        userBo.setGroup_name(deptName);
        userBo.setPersonnel_no(appHolderService.getUser().getCode());
        userBo.setChinese_name(appHolderService.getUser().getName());
        return dingProcessService.getLoginUser(userBo);
    }
}
